package com.topica.network;

import java.util.ArrayList;
import java.util.List;

import org.ksoap2.serialization.PropertyInfo;

import android.content.Context;
import android.util.Log;

import com.topica.database.task.TopicaDBTask;
import com.topica.network.callback.OnSendMarkListener;
import com.topica.object.QuizLogItem;

public class SendMark extends TopicaDBTask {
	private OnSendMarkListener listener;
	private QuizLogItem logItem;
	public SendMark(Context context,QuizLogItem logItem) {
		super(context);
		this.logItem = logItem;
	}

	private static final String METHOD_INFO_COURSE = "updatemark";
	private static final String TAG = "SendMark";

	@Override
	protected Integer doInBackground(Void... params) {
		PropertyInfo pi = new PropertyInfo();
		pi.setName("value");
		String valueSend = "values("+logItem.toString()+")";
		Log.i(TAG, "Value Send = " + valueSend);
		pi.setValue(valueSend);
		List<PropertyInfo> pList = new ArrayList<PropertyInfo>();
		pList.add(pi);
		SoapCaller caller = new SoapCaller();
		int value = caller.updateMark(METHOD_INFO_COURSE, pList);
		Log.e(TAG,"RESPONSE MARK = " + value);
		if (value == 1) {
			return OK;
		} else
			return FAIL;

	}

	@Override
	protected void onPostExecute(Integer result) {
		if (result == OK) {
			listener.onSendMarkDone();
		} else {
			listener.onSendMarkFail();
		}
	}

	public void setOnSendMarkListener(OnSendMarkListener listener) {
		this.listener = listener;
	}
}
